*********************************************************
*********************************************************  
*** GBR 2024 --- JPE Revision Package *******************
*** Code to prepare the dataset of Study 5 **************
*** Public (anonymized) *********************************
*********************************************************

** Note: this code is use for cleaning the dataset for Study 5. It has been 
* already pre-cleaned before, including for anonymization.

clear all
use ".../JPEReplicationPackageDataverse/GBR24DataStudy5.dta"

set more off

destring, replace

** Create control variables
* Woman vs. man indicator (we only have women in this sample)
gen woman=.
replace woman=1 if Genderidentity=="Woman (including Trans Female/Trans Woman)"
label variable woman "Woman (vs. man) indicator: 0No 1Yes"
* Age categories (age variable from Prolific)
gen age60=0  if age!=.
replace age60=1 if age>=60 & age!=.
gen age50=0 if age!=.
replace age50=1 if age>=50 & age<60
gen age40=0  if age!=.
replace age40=1 if age>=40 & age<50
label variable age40 "Age 40-49 indicator: 0No 1Yes"
label variable age50 "Age 50-59 indicator: 0No 1Yes"
label variable age60 "Age 60+ indicator: 0No 1Yes"
* Ethnicity: white vs. non-white indicator
gen white=0 if ethnicity!=""
replace white=1 if ethnicity=="White/Caucasian"
replace white=. if  ethnicity=="CONSENT REVOKED"
label variable white "White (vs. non-white) indicator: 0No 1Yes"


* Create indicator for UK nationality
gen nat_uk=0 if nationality!="" 
replace nat_uk=1 if nationality=="United Kingdom" 
label variable nat_uk "Nationality indicator: 0Non-UK 1UK"

* Create indicator for students
gen student=0 if student_status=="No"
replace student=1 if student_status=="Yes"
label variable student "Student indicator: 0No 1Yes"

* Create employment status indicators
gen employed=.
replace employed=1 if employment_status=="Full-Time"
replace employed=0 if employment_status=="Not in paid work (e.g. homemaker', 'retired or disabled)"
replace employed=0 if employment_status=="Other"
replace employed=0 if employment_status=="Due to start a new job within the next month"
replace employed=0 if employment_status=="Part-Time"
replace employed=0 if employment_status=="Unemployed (and job seeking)"
label variable employed "E: Employed full time indicator: 0No 1Yes"

gen unemployed=.
replace unemployed=0 if employment_status=="Full-Time"
replace unemployed=0 if employment_status=="Not in paid work (e.g. homemaker', 'retired or disabled)"
replace unemployed=0 if employment_status=="Other"
replace unemployed=0 if employment_status=="Due to start a new job within the next month"
replace unemployed=0 if employment_status=="Part-Time"
replace unemployed=1 if employment_status=="Unemployed (and job seeking)"
label variable unemployed "E: Unemployed indicator: 0No 1Yes"

gen parttime=.
replace parttime=0 if employment_status=="Full-Time"
replace parttime=0 if employment_status=="Not in paid work (e.g. homemaker', 'retired or disabled)"
replace parttime=0 if employment_status=="Other"
replace parttime=0 if employment_status=="Due to start a new job within the next month"
replace parttime=1 if employment_status=="Part-Time"
replace parttime=0 if employment_status=="Unemployed (and job seeking)"
label variable parttime "E: Employed part time indicator: 0No 1Yes"

gen notInPaidJob=.
replace notInPaidJob=0 if employment_status=="Full-Time"
replace notInPaidJob=1 if employment_status=="Not in paid work (e.g. homemaker', 'retired or disabled)"
replace notInPaidJob=0 if employment_status=="Other"
replace notInPaidJob=0 if employment_status=="Due to start a new job within the next month"
replace notInPaidJob=0 if employment_status=="Part-Time"
replace notInPaidJob=0 if employment_status=="Unemployed (and job seeking)"
label variable notInPaidJob "E: Not in paid job indicator: 0No 1Yes"

gen otheremployment=.
replace otheremployment=0 if employment_status=="Full-Time"
replace otheremployment=0 if employment_status=="Not in paid work (e.g. homemaker', 'retired or disabled)"
replace otheremployment=1 if employment_status=="Other"
replace otheremployment=1 if employment_status=="Due to start a new job within the next month"
replace otheremployment=0 if employment_status=="Part-Time"
replace otheremployment=0 if employment_status=="Unemployed (and job seeking)"
label variable otheremployment "E: Other employement status indicator: 0No 1Yes"

** Create variable to identify each study, and ID variable (5,000,000 range 
* denotes IDs in Study 5)
gen study=5
gen id=5000000 + _n
label variable study "Study: 1Study1 2Study2 3Study3 4Study4 5Study5 6Study6"
label variable id "Worker ID: 1,000,000 range for Study 1, 2,000,000 for Study 2,..."

** Create variables with numerical encoding
tab Q_motiva
gen motivation_change=0 if Q_motiva=="My work motivation decreased a lot"
replace motivation_change=1 if Q_motiva=="My work motivation decreased"
replace motivation_change=2 if Q_motiva=="My work motivation stayed around the same"
replace motivation_change=3 if Q_motiva=="My work motivation increased"
replace motivation_change=4 if Q_motiva=="My work motivation increased a lot"
label variable motivation_change "Motivation change: 0DecreaseLot 1Decrease 2Same 3Increase 4IncreaseLot"

tab Q_hours1_formalhours
gen formal_hours_change=0 if Q_hours1_formalhours=="I reduced them by around 25 hours or more"
replace formal_hours_change=1 if Q_hours1_formalhours=="I reduced them by around 20 hours"
replace formal_hours_change=2 if Q_hours1_formalhours=="I reduced them by around 15 hours"
replace formal_hours_change=3 if Q_hours1_formalhours=="I reduced them by around 10 hours"
replace formal_hours_change=4 if Q_hours1_formalhours=="I reduced them by around 5 hours"
replace formal_hours_change=5 if Q_hours1_formalhours=="I reduced them by around 2 hours"
replace formal_hours_change=6 if Q_hours1_formalhours=="No, I did not"
replace formal_hours_change=7 if Q_hours1_formalhours=="I increased them by around 2 hours"
replace formal_hours_change=8 if Q_hours1_formalhours=="I increased them by around 5 hours"
replace formal_hours_change=9 if Q_hours1_formalhours=="I increased them by around 10 hours"
replace formal_hours_change=10 if Q_hours1_formalhours=="I increased them by around 15 hours"
replace formal_hours_change=11 if Q_hours1_formalhours=="I increased them by around 20 hours"
replace formal_hours_change=12 if Q_hours1_formalhours=="I increased them by around 25 hours or more"
label variable formal_hours_change "Formal hours change: 0Decrease25h+ 3Dec10h 6Same 9Inc10h 12Increase25h+"

tab Q_hours3_breaks
gen break_length_change=0 if Q_hours3_breaks=="longer"
replace break_length_change=1 if Q_hours3_breaks=="no change"
replace break_length_change=2 if  Q_hours3_breaks=="shorter"
label variable break_length_change "Break length change: 0Longer 1Same 2Shorter "

tab Q_produc
gen workproductivity_change=0 if Q_produc=="My work productivity decreased a lot"
replace workproductivity_change=1 if Q_produc=="My work productivity decreased"
replace workproductivity_change=2 if Q_produc=="My work productivity stayed around the same"
replace workproductivity_change=3 if Q_produc=="My work productivity increased"
replace workproductivity_change=4 if Q_produc=="My work productivity increased a lot"
label variable workproductivity_change "Work productivity change: 0DecreaseLot 1Decrease 2Same 3Increase 4IncreaseLot"

tab Q_leavejob 
gen leavejob_anyreason=0 if Q_leavejob=="No, I did not"
replace leavejob_anyreason=1 if Q_leavejob=="Yes, around 1.5 year after or more"
replace leavejob_anyreason=2 if Q_leavejob=="Yes, around 1 year after"
replace leavejob_anyreason=3 if Q_leavejob=="Yes, around 6 months after"
replace leavejob_anyreason=4 if Q_leavejob=="Yes, around 3 months after"
replace leavejob_anyreason=5 if Q_leavejob=="Yes, around 1 month after"
replace leavejob_anyreason=6 if Q_leavejob=="Yes, around 1 week after"
label variable leavejob_anyreason "Leave job for any reason: 0No 1Yes1.5y+ 2Yes1y 3Yes6m 4Yes3m 5Yes1m 6Yes1w"

tab Q_motiva_duration
gen motivation_change_duration=0 if Q_motiva_duration=="Around 1 week"
replace motivation_change_duration=1 if Q_motiva_duration=="Around 1 month"
replace motivation_change_duration=2 if Q_motiva_duration=="Around 3 months"
replace motivation_change_duration=3 if Q_motiva_duration=="Around 6 months"
replace motivation_change_duration=4 if Q_motiva_duration=="Around 1 year"
replace motivation_change_duration=5 if Q_motiva_duration=="Around 1.5 year or more"
label variable motivation_change_duration "Duration motivation change: 0:1w 1:1m 2:3m 3:6m 4:1y 5:1.5y+"

tab Q_hours_duration 
gen hours_change_duration=0 if Q_hours_duration=="Around 1 week"
replace hours_change_duration=1 if Q_hours_duration=="Around 1 month"
replace hours_change_duration=2 if Q_hours_duration=="Around 3 months"
replace hours_change_duration=3 if Q_hours_duration=="Around 6 months"
replace hours_change_duration=4 if Q_hours_duration=="Around 1 year"
replace hours_change_duration=5 if Q_hours_duration=="Around 1.5 year or more"
label variable hours_change_duration "Duration (formal/informal) hours change: 0:1w 1:1m 2:3m 3:6m 4:1y 5:1.5y+"

tab Q_produc_duration
gen workproductivity_change_duration=0 if Q_produc_duration=="Around 1 week"
replace workproductivity_change_duration=1 if Q_produc_duration=="Around 1 month"
replace workproductivity_change_duration=2 if Q_produc_duration=="Around 3 months"
replace workproductivity_change_duration=3 if Q_produc_duration=="Around 6 months"
replace workproductivity_change_duration=4 if Q_produc_duration=="Around 1 year"
replace workproductivity_change_duration=5 if Q_produc_duration=="Around 1.5 year or more"
label variable workproductivity_change_duration "Duration work productivity change: 0:1w 1:1m 2:3m 3:6m 4:1y 5:1.5y+"

** Save dataset
save ".../JPEReplicationPackageDataverse/GBR24DataCleanStudy5.dta", replace
